package com.imooc.pay.config.pay;

import com.lly835.bestpay.config.AliPayConfig;
import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component("basePayConfig")
public class BasePayConfig {

    @Resource(name = "wxConfig")
    private WxConfig wxConfig;

    @Resource(name = "aliConfig")
    private AliConfig aliConfig;


    @Bean(name = "wxPayConfig")
    public WxPayConfig provideWxPayConfig() {
        //微信支付配置
        WxPayConfig wxPayConfig = new WxPayConfig();
        wxPayConfig.setAppId(wxConfig.getAppid());          //公众号Id
        //支付商户资料
        wxPayConfig.setMchId(wxConfig.getMchid());
        wxPayConfig.setMchKey(wxConfig.getMchkey());
        wxPayConfig.setNotifyUrl(wxConfig.getNotifyUrl());
        return wxPayConfig;
    }

    @Bean(name = "aliPayConfig")
    public AliPayConfig provideAliPayConfig() {
        //支付宝网页&移动应用 支付配置
        AliPayConfig aliPayConfig = new AliPayConfig();
        //支付商户资料
        aliPayConfig.setAppId(aliConfig.getAppid());
        aliPayConfig.setPrivateKey(aliConfig.getPrivateKey());
        aliPayConfig.setAliPayPublicKey(aliConfig.getAliPayPublicKey());
        aliPayConfig.setNotifyUrl(aliConfig.getNotifyUrl());
        aliPayConfig.setReturnUrl(aliConfig.getReturnUrl());
        return aliPayConfig;
    }

    @Bean(name = "bestPayService")
    public BestPayServiceImpl provideBestPayService() throws Throwable {
        //BestPayServiceImpl是支付类，里面包含支付的方法
        return new BestPayServiceImpl();
    }

}
